import 'package:flutter/widgets.dart';
import 'package:test/application.dart';

class AppNavigator {
  static final List<String> _needLoginRouteName = [];

  static pushNamed(BuildContext context, String name, {Object arguments}) {
    if (_needLoginRouteName.indexOf(name) > -1 &&
        (GlobalData.getToken() == null || GlobalData.getToken().isEmpty)) {
      Navigator.of(context).pushNamed(
        RouterName.login,
      );
      return;
    }
    Navigator.of(context).pushNamed(name, arguments: arguments);
  }

  /// 打开应用链接
  static openLink(BuildContext context, String link, {dynamic params}) {
    if (link == null || link.isEmpty) {
      return;
    }
    if (link.startsWith("http://") || link.startsWith("https://")) {
      params["url"] = link;
      // pushNamed(context, RouterName.appWebview, arguments: params);
    } else {
      pushNamed(context, link, arguments: params);
    }
  }
}
